package cn.kz.hrm.web.controller;

import cn.kz.hrm.dto.PhoneRegisterCode;
import cn.kz.hrm.service.IVerifycodeService;
import cn.kz.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *获取图片的验证码
 */
@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService verifycodeService;


    /**
     * 获取图片验证码,因为定义了全局的异常，所以可以不用再try catch
     * @param imageCodeKey
     * @return
     */
    @RequestMapping(value = "/imageCode/{key}",method = RequestMethod.GET)
    public AjaxResult getImageCode(@PathVariable("key") String imageCodeKey){
            String code = verifycodeService.getImageCode(imageCodeKey);
            return AjaxResult.me().setResultObj(code);
    }

    /**
     * 获取手机注册验证码，因为定义了全局的异常所以，可以不用再try catch
     * @param phoneRegisterCode
     * @return
     */
    @RequestMapping(value = "/sendSmsCode",method = RequestMethod.POST)
    public AjaxResult getSmsCode(@RequestBody PhoneRegisterCode phoneRegisterCode){
            verifycodeService.getSmsCode(phoneRegisterCode);
            return AjaxResult.me();
    }
}
